package com.nhc.model;

import com.nhc.database.dbmodel.SystemAllInfo;
import com.nhc.database.manager.SystemCenter;

import java.util.ArrayList;

import zuo.biao.library.util.JSON;

public class TransParaSevenFileHandle {
    private static TransParaSevenFileHandle instance = new TransParaSevenFileHandle();
    private ArrayList<TransParaSeven> mListTransParaSeven = new ArrayList<TransParaSeven>();

    public static TransParaSevenFileHandle getInstance() {
        return instance;
    }

    public ArrayList<TransParaSeven> getListr() {
        return mListTransParaSeven;
    }

    public TransParaSevenFileHandle() {
        load();
    }

    public TransParaSeven getListTransParaSeven(int mode) {
        if (mode < 0 || mode >= mListTransParaSeven.size()) {
            mode = 0;
        }
        return mListTransParaSeven.get(mode);
    }

    public void load() {
        mListTransParaSeven.clear();

        int Max = TransParaSeven.m_ElipsInfoList.length;
        for (int i = 0; i < Max; i++) {
            TransParaSeven tps = new TransParaSeven(i, TransParaSeven.m_ElipsInfoList[i]);
            SystemAllInfo sInfo = SystemCenter.getInstance().getSysInfo("TransParaSeven_N" + i);
            if (sInfo != null) {
                String strTransParaSeven = sInfo.getContent();
                if (strTransParaSeven.length() > 1) {
                    try {
                        com.alibaba.fastjson.JSONObject data = JSON.parseObject(strTransParaSeven);
                        if (data != null) {
                            tps = JSON.parseObject(data, TransParaSeven.class);
                        }
                    } catch (Exception e1) {

                    }
                }
            }
            mListTransParaSeven.add(tps);
        }
    }

    public void save() {
        int size = mListTransParaSeven.size();
        for (int i = 0; i < size; i++) {
            TransParaSeven tps = mListTransParaSeven.get(i);
            String strTransParaSeven = JSON.toJSONString(tps);
            SystemAllInfo sInfo = SystemCenter.getInstance().getSysInfo("TransParaSeven_N" + i);
            if (sInfo == null) {
                sInfo = new SystemAllInfo(null, "TransParaSeven_N" + i, strTransParaSeven);
            } else {
                sInfo.setContent(strTransParaSeven);
            }
            SystemCenter.getInstance().saveSysInfo(sInfo);
        }
    }


}

